//
//  YunTypeVC.m
//  reSearchDemo
//
//  Created by 云库 on 15/10/22.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "YunTypeVC.h"
#import "PersonalPlatform.h"

@interface YunTypeVC ()
{
    NSMutableArray *_btnArr;
    NSInteger _typeid;
}


@property (strong, nonatomic) NSString *account;
@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *email;
@property (strong, nonatomic) NSString *password;

@property (weak, nonatomic) IBOutlet UIButton *Personal;
@property (weak, nonatomic) IBOutlet UIButton *Enterprise;
@property (weak, nonatomic) IBOutlet UIButton *Commerce;
@property (weak, nonatomic) IBOutlet UIButton *Public;
@property (weak, nonatomic) IBOutlet UIButton *Common;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;

@end

@implementation YunTypeVC

- (id) initWithAccount:(NSString *)account name:(NSString *)name email:(NSString *)email password:(NSString *)password {
    self = [super init];
    if (self) {
        self.account = account;
        self.name = name;
        self.email = email;
        self.password = password;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.title=@"云平台性质";
    
    _btnArr=[[NSMutableArray alloc]initWithObjects:self.Personal,self.Enterprise,self.Commerce,self.Public,self.Common, nil];
    
    self.Personal.selected = NO;
    [self.Personal setTintColor:[UIColor clearColor]];
    [self.Personal setImage:[UIImage imageNamed:@"btn_radio_n@2x"] forState:UIControlStateNormal];
    [self.Personal setImage:[UIImage imageNamed:@"btn_radio_s@2x"] forState:UIControlStateSelected];
    self.Personal.tag=0;
    [self.Personal addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.Enterprise.selected = NO;
    [self.Enterprise setTintColor:[UIColor clearColor]];
    [self.Enterprise setImage:[UIImage imageNamed:@"btn_radio_n@2x"] forState:UIControlStateNormal];
    [self.Enterprise setImage:[UIImage imageNamed:@"btn_radio_s@2x"] forState:UIControlStateSelected];
    self.Enterprise.tag=1;
    [self.Enterprise addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.Commerce.selected = NO;
    [self.Commerce setTintColor:[UIColor clearColor]];
    [self.Commerce setImage:[UIImage imageNamed:@"btn_radio_n@2x"] forState:UIControlStateNormal];
    [self.Commerce setImage:[UIImage imageNamed:@"btn_radio_s@2x"] forState:UIControlStateSelected];
    self.Commerce.tag=2;
    [self.Commerce addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.Public.selected = NO;
    [self.Public setTintColor:[UIColor clearColor]];
    [self.Public setImage:[UIImage imageNamed:@"btn_radio_n@2x"] forState:UIControlStateNormal];
    [self.Public setImage:[UIImage imageNamed:@"btn_radio_s@2x"] forState:UIControlStateSelected];
    self.Public.tag=3;
    [self.Public addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.Common.selected = NO;
    [self.Common setTintColor:[UIColor clearColor]];
    [self.Common setImage:[UIImage imageNamed:@"btn_radio_n@2x"] forState:UIControlStateNormal];
    [self.Common setImage:[UIImage imageNamed:@"btn_radio_s@2x"] forState:UIControlStateSelected];
    self.Common.tag=4;
    [self.Common addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    //下一步按钮
    self.sureBtn.tag=1000;
    self.sureBtn.selected=NO;
    self.sureBtn.userInteractionEnabled=NO;
    [self.sureBtn addTarget:self action:@selector(sureBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}

//选中按钮
-(void)selectBtnAction:(UIButton *)sender {
    
    _typeid=sender.tag;
    
    UIButton *sure = (UIButton *)[self.view viewWithTag:1000];
    
    for (UIButton *btn in _btnArr) {
        btn.selected = NO;

    }
    
    sender.selected = YES;
    if (sender.selected) {
        self.sureBtn.userInteractionEnabled=YES;
        sure.backgroundColor = [UIColor blueColor];
        [sure setTintColor:[UIColor clearColor]];
    }
    
}
//下一步按键处理方法
//-(void)sureBtnAction:(UIButton *)sender{
//    DLog(@"下一步");
//    
//    
//    
////    [self pushViewController:[PersonalPlatform new]];
//    
//    [self pushViewController:[[PersonalPlatform alloc] initWith:type]];
//}

//确定按钮
-(void)sureBtnAction:(UIButton *)sender {
    Platform_Type type = 0;
    if (self.Personal.selected) {
        type = personalPlatform;
    } else if (self.Enterprise.selected) {
        type = EnterprisePlatform;
    } else if (self.Commerce.selected) {
        type = BusinessAssociation;
    } else if (self.Public.selected) {
        type = BusinessUnit;
    } else if (self.Common.selected) {
        type = PublicService;
    } else {
        return;
    }

    [self pushViewController:[[PersonalPlatform alloc] initWithPlatformType:type account:self.account name:self.name email:self.email password:self.password]];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
